package com.zyc.app.woa;

import android.app.Application;
import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.zyc.app.woa.utils.AsyncTaskExecutor;
import com.zyc.app.woa.utils.Caches;

import java.io.File;

/**
 * Author: yingchang.zhang
 * Date  : 2014/11/28
 */
public class WoaApp extends Application {
    private static WoaApp sApp;

    @Override
    public void onCreate() {
        super.onCreate();
        sApp = this;
        Caches.init(this);
        initImageLoader();
        AsyncTaskExecutor.init();
        SubscribeAccounts.init(this);
    }

    public static WoaApp getApp() {
        return sApp;
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }

    public static void initImageLoader() {
        DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
                .cacheOnDisk(true).cacheInMemory(true)
                .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
                .displayer(new FadeInBitmapDisplayer(300)).build();
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApp().getApplicationContext())
                .defaultDisplayImageOptions(defaultOptions)
                .memoryCache(new WeakMemoryCache())
                .diskCache(new LruDiscCache(new File(WxConfig.CACHE_PICS_PATH), new HashCodeFileNameGenerator(), WxConfig.MAX_CACHE_SIZE))
                .build();
        ImageLoader.getInstance().init(config);
    }

}
